package com.product.android.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;

import com.common.android.utils.HeapObserverUtils;
import com.flurry.android.FlurryAgent;
import com.product.android.business.config.Configuration;
import com.product.android.utils.LogUtils;

public class BaseActivity extends BaseReceiveActivity {	
	@Override
	 protected void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    _onCreate(savedInstanceState);
	 }
	
	protected boolean _onCreate(Bundle savedInstanceState) {
		setSavedData(savedInstanceState);
		return true;
	}
	
	protected void setSavedData(Bundle savedInstanceState) {

	}
	
	protected void goTo(Class<?> cls){
		Intent intent = new Intent(BaseActivity.this,cls);
		this.startActivity(intent);
	}
	
	public void goTo(Class<?> cls,Bundle bundle){
		Intent intent = new Intent(BaseActivity.this,cls);
		intent.putExtras(bundle);
		this.startActivity(intent);
	}
	
	
	protected void toActivity(Class<?> cls,boolean flag){
		Intent intent = new Intent();
		intent.setClass(this, cls);			
		startActivity(intent);		
		if(flag){
			finish();
		}
	}
	
	protected void toActivity(Class<?> cls,Bundle bundle){
		Intent intent = new Intent();
		intent.putExtras(bundle);
		intent.setClass(this, cls);			
		startActivity(intent);		
	}
	
	protected void initComponent(){}
	protected void initComponentValue(){}
	protected void initEvent(){}
	
	@Override
	protected void onStart() {
		super.onStart();
		FlurryAgent.setReportLocation(false);
		FlurryAgent.onStartSession(this,Configuration.FLURRYKEY );
	}
	
	@Override
	public void onResume(){
		super.onResume();
		registerReceiverBroad();
		HeapObserverUtils.check(this.getClass().getName());
	}
	
	@Override
	protected void onPause() {
		super.onPause();
		unRegisterReceiverBroad();
	}
	
	@Override
	protected void onStop(){
		super.onStop();
		FlurryAgent.onEndSession(this);
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
	}
	
	
	public void hideSoftInput(EditText editText){
		try {
			InputMethodManager manager=(InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
			manager.hideSoftInputFromWindow(editText.getWindowToken(), 0);	
		} catch (Exception e) {
			LogUtils.d("debug", "hideSoftInput:"+e.getMessage());
		}
	}
	
	public void showSoftInput(View view){
		try {
			InputMethodManager manager=(InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
			manager.showSoftInput(view, 0);
		} catch (Exception e) {
			LogUtils.d("debug", "showSoftInput:"+e.getMessage());
		}
	}
	
	public void hideSoftInput(){
		View view=getCurrentFocus();
		if (view!=null){
			if (view instanceof EditText){
				hideSoftInput((EditText) view);
			}
		}
	}
}